#include <stdio.h>
#include <ctype.h>
#include <stdbool.h>

int main() {
	char ch, first_name = 0, last_name[20] = { 0 };
	bool begin_last_name = false;
	int index = 0;

	printf("Enter a first and last name: ");

	while ((ch = getchar()) != '\n')
	{
		if (ch == ' ')
		{
			if (last_name[0]) {
				break; // 结束读取姓氏
			}
			else if (first_name)
			{
				begin_last_name = true; // 结束读取名字
			}
		}
		else 
		{
			if (first_name == 0)
			{
				first_name = toupper(ch); // 写入名字首字母
			}
			else if (begin_last_name) {
				last_name[index++] = ch;
			}
		}
	}
	
	index = 0;
	printf("You entered the name: ");
	while (ch = last_name[index++])
	{
		if (index == 1)
		{
			ch = toupper(ch);
		}
		putchar(ch);
	}
	printf(", %c.\n", first_name);
	
	return 0;
}
